[xml]$nugetConfig = Get-Content .\NuGet.Config

$choices = [System.Management.Automation.Host.ChoiceDescription[]](
	(New-Object System.Management.Automation.Host.ChoiceDescription "&Add API Key","Add an API Key for this URL"),
	(New-Object System.Management.Automation.Host.ChoiceDescription "&Skip","Skip pushing to this URL"))

$nugetConfig.configuration.packageSources.add | ForEach-Object {
	$url = $_.value
	$firstAnswer = $Host.UI.PromptForChoice(("Would you like to try adding an API key for " + $Url + "?"), "", $choices, (1))

	if ($firstAnswer -eq 0) {
		$fields = new-object "System.Collections.ObjectModel.Collection``1[[System.Management.Automation.Host.FieldDescription]]"

		$f = New-Object System.Management.Automation.Host.FieldDescription "API Key for $Url"
		$f.SetParameterType( [System.Security.SecureString] )

		$fields.Add($f)

		$results = $Host.UI.Prompt( "Add API Key", "", $fields )
		$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($results["API Key for $Url"]))

		# Add API Key to config file
		Write-Host (.\NuGet.exe setApiKey $pass -Source $Url)
	}
	else {
		Write-Host "Skipping..." -ForegroundColor Gray
		$ExitCode = 2
	}
}
Write-Host "Done!" -ForegroundColor Gray
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")